import { $get, $put } from '@js/request'
import { CaseSchema } from '@src/components/schema/caseSchema'
import { ConditionSchema } from '@src/components/schema/condition'
import { SeriesSchema } from '@src/components/schema/seriesCase'

export async function getCaseListRequest (d: { condition: ConditionSchema[], page: number, limit: number }): Promise<{ list: CaseSchema[], total: number }> {
  const res = await $get('/api/commission/case', {
    condition: JSON.stringify(d.condition),
    page: d.page,
    limit: d.limit
  })
  const list: CaseSchema[] = res.data.list
  list.forEach((li, i) => {
    li.orderno = (d.page - 1) * d.limit + i + 1
  })
  return res.data
}

// 添加案件请求
export async function addCaseRequest (id: string, keys: React.Key[]): Promise<void> {
  const res = await $put(`/api/commission/caseserie/add_case/${id}`, {
    caseids: keys.join()
  })
  return res.data
}

// 获取系列案详情
export async function getSeriesRequest (id: string): Promise<SeriesSchema> {
  const res = await $get(`/api/commission/caseserie/${id}`)
  return res.data
}
